// view/index/addyuan/addyuan.js
let app = getApp()
let yuming = app.globalData.yuming
let mobile = app.globalData.mobile
let sfzza = app.globalData.sfzza
var chaninese = /[^\u4E00-\u9FA5]/g
const request = require('../../config/request');
const util = require('../../config/util');
var jiankaishi = util.ynian(new Date())
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    xuan_list: [],
    isjkz: false,
    isbyz: false,
    iszcz: false,
    iszgz: false,
    s2: false,
    yuming: yuming,
    yiyao: '',
    heights: "",
    buttonClicked: false,
    title: '修改员工',
    id: '', //修改员工
    xingming: '', //姓名
    dianhua: '', //电话
    shenfenz: '', //身份证号
    zhiweiid: '', //职位id
    qutime: '', //取证时间
    daotime: '', //有效期至
    zhiguo: '请选择职位',
    // zhilist: [{ name: '店长', id: 2}, {  name: '员工', id: 3 }], //职位
    zhiindex: 0, //职位index
    date: '请选择健康证取证时间', //开始
    dates: '请选择健康证有效时间', //结束
    jkz: '', //健康证照片
    cyz: '', //从业证图片
    wujkz: '',
    wucyz: '',
    cyzdatequ: '请选择从业取证时间',
    cyzdatedao: '请选择从业证有效期',
    jkzzjlx: '', //健康证证件类型
    cyzzjlx: '', //从业证证件类型
    fdaaa: '',
    fdimg: '',
    Position: '', //职位
    bytime: '请选择毕业证取证时间',
    bytimes: '',
    zgtime: '请选择注册证取证时间',
    zgtimes: '请选择注册证到期时间',
    byz: '',
    zgz: '',
    wuzgz: '',
    wubyz: '',
    zgzs: '',
    jkis_dian: false,
    byis_dian: false,
    zcis_dian: false,
    zgis_dian: false,
    otherszheng: false,
    otherimg: "",
    wuotherimg: "",

    jiankaishi: jiankaishi, //健康证的开始时间
    zhucekaishi: '2020-01-01', //注册开始时间
    jinghe_id: '',
    otherqu: '请选择其他证件取证时间', //其他证件
    otheryou: '请选择其他证件有效期', //其他证件
    thatImage: '',
    thatStartime: '',
    thatEndtime: ''
  },
  bindzigesa: function (e){
    this.setData({

    zgtimes: e.detail.value,
    zgis_dian: true
  })

  },
  otheryoudao: function (e) {
    if (new Date(e.detail.value).getTime() < Date.parse(new Date())) {
      wx.showToast({
        title: '有效期不可小于当前时间',
        icon: 'none'
      })
      this.setData({
        otheryou: '请选择注册证有效期',
        // zcis_dian: false
      })
    } else {
      this.setData({
        otheryou: e.detail.value,
        otheryou: e.detail.value,
        // zcis_dian: true
      })
    }
  },
  bindotherqu: function (e) {
    this.setData({
      otherqu: e.detail.value,
      otherqu: e.detail.value,
      // zcis_dian: true
    })
  },
  xizheng(e) {
    var index = e.currentTarget.dataset.index;
    var item = this.data.xuan_list
    item[index].checked = !item[index].checked
    if (this.data.jinghe_id == 176) {
      if (index == 0) {
        if (this.data.xuan_list[0].checked) {
          this.setData({
            isjkz: true
          })
        } else {
          this.setData({
            isjkz: false
          })
        }
      }
      if (index == 1) {
        if (this.data.xuan_list[1].checked) {
          this.setData({
            isbyz: true
          })
        } else {
          this.setData({
            isbyz: false
          })
        }
      }
      if (index == 2) {
        if (this.data.xuan_list[2].checked) {
          this.setData({
            iszcz: true
          })
        } else {
          this.setData({
            iszcz: false
          })
        }
      }
      if (index == 3) {
        if (this.data.xuan_list[3].checked) {
          this.setData({
            iszgz: true
          })
        } else {
          this.setData({
            iszgz: false
          })
        }
      }
    }
    if (this.data.yiyao == 6) {
      if (index == 0) {
        if (this.data.xuan_list[0].checked) {
          this.setData({
            isjkz: true
          })
        } else {
          this.setData({
            isjkz: false
          })
        }
      }
      if (index == 1) {
        if (this.data.xuan_list[1].checked) {
          this.setData({
            iszcz: true
          })
        } else {
          this.setData({
            iszcz: false
          })
        }
      }
      if (index == 2) {
        if (this.data.xuan_list[2].checked) {
          this.setData({
            iszgz: true
          })
        } else {
          this.setData({
            iszgz: false
          })
        }
      }
      if (index == 3) {
        if (this.data.xuan_list[3].checked) {
          this.setData({
            otherszheng: true
          })
        } else {
          this.setData({
            otherszheng: false
          })
        }
      }
    } else {
      if (index == 0) {
        if (this.data.xuan_list[0].checked) {
          this.setData({
            isjkz: true
          })
        } else {
          this.setData({
            isjkz: false
          })
        }
      }
      if (index == 1) {
        if (this.data.xuan_list[1].checked) {
          this.setData({
            iszcz: true
          })
        } else {
          this.setData({
            iszcz: false
          })
        }
      }
      if (index == 2) {
        if (this.data.xuan_list[2].checked) {
          this.setData({
            // iszgz: true
            otherszheng: true

          })
        } else {
          this.setData({
            // iszgz: false
            otherszheng: false

          })
        }
      }
      if (index == 3) {
        if (this.data.xuan_list[3].checked) {
          this.setData({
            otherszheng: true
          })
        } else {
          this.setData({
            otherszheng: false
          })
        }
      }
    }
    this.setData({
      xuan_list: item
    })
  },
  showModal(e) {
    var aaa = e.currentTarget.dataset.aaa
    var img = e.currentTarget.dataset.img
    this.setData({
      fdaaa: aaa,
      fdimg: img
    })
    let {
      type
    } = e.currentTarget.dataset, va = '';
    if (type == 's2') {
      va = "s2";
    }
    this.setData({
      [va]: true
    })
  },
  confirmbtn(e) {
    console.log(e)
    console.log('点击了从新上传！')
    var aaa = this.data.fdaaa
    var that = this;
    this.myChooseImage(1).then(res => {
      const tempFilePaths = res.tempFilePaths
      this.myUploadImg(tempFilePaths[0], 'file').then(res => {
        var data = JSON.parse(res.data)
        wx.showToast({
          title: data.msg,
          icon: 'none'
        })
        var urls = data.httpUrl + data.imgUrl
        if (aaa == 0) {
          that.setData({
            jkz: urls,
            wujkz: data.imgUrl,
            jkis_dian: true,
          });
        }
        if (aaa == 1) {
          that.setData({
            cyz: urls,
            wucyz: data.imgUrl,
            zcis_dian: true
          });
        }
        if (aaa == 2) {
          that.setData({
            byz: urls,
            wubyz: data.imgUrl,
            byis_dian: true
          });
        }
        if (aaa == 3) {
          that.setData({
            zgz: urls,
            wuzgz: data.imgUrl,
            zgis_dian: true
          });
        }
        if (aaa == 4) {
          that.setData({
            otherimg: urls,
            wuotherimg: data.imgUrl,
            // zgis_dian: true
          });
        }
      })
    })

  },
  cancelBtn() {
    console.log('点击了放大！')
    wx.previewImage({
      urls: [this.data.fdimg]
    })
  },
  getIptValue(e) {
    console.log(e.detail)
  },
  // 员工详情
  ygxq(e) {
    var that = this
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'shop/shopFindStaff', {
      id: that.data.id,
      shopId: wx.getStorageSync('shopId')
    }, 'POST').then(res => {
      if (res.data.code == 200) {
        wx.hideLoading();
        var data = res.data.data
        that.setData({
          xingming: data.Name,
          dianhua: data.Phone,
          shenfenz: data.idNumber,
          Position: data.Position,
        })
        var xuan_list = that.data.xuan_list;
        if (that.data.jinghe_id == 176) {
          // 健康证
          if (data.healthyImage == '' || data.healthyImage == null) {
            xuan_list[0].checked = false;
            that.setData({
              isjkz: false,
              date: '请选择健康证取证时间',
              dates: '请选择健康证有效时间',
              jkz: '',
              wujkz: '',
              xuan_list: xuan_list
            })
          } else {
            xuan_list[0].checked = true;
            that.setData({
              isjkz: true,
              date: data.obtainTime,
              dates: data.effectiveTime,
              jkz: data.healthyImage_thum,
              wujkz: data.healthyImage,
              xuan_list: xuan_list
            })
          }
          // 毕业证
          if (data.graduationPhoto == '' || data.graduationPhoto == null) {
            xuan_list[1].checked = false;
            that.setData({
              isbyz: false,
              bytime: '请选择毕业证取证时间',
              bytimes: '',
              byz: '',
              wubyz: '',
              xuan_list: xuan_list
            })
          } else {
            xuan_list[1].checked = true;
            that.setData({
              isbyz: true,
              bytime: data.graduationPuttime,
              bytimes: data.graduationPuttime,
              byz: data.graduationPhoto_thum,
              wubyz: data.graduationPhoto,
              xuan_list: xuan_list
            })
          }
          // 注册证
          if (data.registerPhoto == '' || data.registerPhoto == null) {
            if (that.data.yiyao == 6) {
              xuan_list[2].checked = false;
              that.setData({
                iszcz: false,
                cyz: '',
                wucyz: '',
                xuan_list: xuan_list,
                cyzdatequ: '请选择注册证取证时间',
                cyzdatequs: '',
                cyzdatedao: '请选择注册证有效期',
                cyzdatedaos: '',
              })
            } else {
              xuan_list[2].checked = false;
              that.setData({
                iszcz: false,
                cyz: '',
                wucyz: '',
                cyzdatequ: '请选择从业证取证时间',
                cyzdatequs: '',
                cyzdatedao: '请选择从业证有效期',
                cyzdatedaos: '',
                xuan_list: xuan_list,
              })
            }
          } else {
            xuan_list[2].checked = true;
            that.setData({
              iszcz: true,
              cyzdatequ: data.registerPuttime,
              cyzdatequs: data.registerPuttime,
              cyzdatedao: data.registerEndtime,
              cyzdatedaos: data.registerEndtime,
              cyz: data.registerPhoto_thum,
              wucyz: data.registerPhoto,
              xuan_list: xuan_list,
            })
          }
          // 资格证
          if (data.practiceImage == '' || data.practiceImage == null) {
            xuan_list[3].checked = false;
            that.setData({
              iszgz: false,
              zgtime: '请选择毕业证取证时间',
              zgtimes: '',
              zgz: '',
              wuzgz: '',
              xuan_list: xuan_list,
            })
          } else {
            xuan_list[3].checked = true;
            that.setData({
              iszgz: true,
              zgtimes: data.practiceendTime,
              zgtime: data.practicestarTime,
              zgz: data.practiceImage_thum,
              wuzgz: data.practiceImage,
              xuan_list: xuan_list,
            })
          }
        } else {
          this.setData({
            cyzzjlx: data.practiceDcment
          })
          // 健康证
          if (data.healthyImage == '' || data.healthyImage == null) {
            xuan_list[0].checked = false;
            that.setData({
              isjkz: false,
              date: '请选择健康证取证时间',
              dates: '请选择健康证有效时间',
              jkz: '',
              wujkz: '',
              xuan_list: xuan_list
            })
          } else {
            xuan_list[0].checked = true;
            that.setData({
              isjkz: true,
              date: data.obtainTime,
              dates: data.effectiveTime,
              jkz: data.healthyImage_thum,
              wujkz: data.healthyImage,
              xuan_list: xuan_list
            })
          }

          if (that.data.yiyao == 6) {
            // 注册证
            if (data.registerPhoto == '' || data.registerPhoto == null) {
              // if (that.data.yiyao == 6) {
              //   xuan_list[1].checked = false;
              //   that.setData({
              //     iszcz: false,
              //     cyz: '',
              //     wucyz: '',
              //     xuan_list: xuan_list,
              //     cyzdatequ: '请选择注册证取证时间',
              //     cyzdatequs: '',
              //     cyzdatedao: '请选择注册证有效期',
              //     cyzdatedaos: '',
              //   })
              // } else {
              xuan_list[2].checked = false;
              that.setData({
                // iszcz: false,
                // cyz: '',
                // wucyz: '',
                // cyzdatequ: '请选择注册证取证时间',
                // cyzdatequs: '',
                // cyzdatedao: '请选择注册证有效期',
                // cyzdatedaos: '',
                // xuan_list: xuan_list,
                
                iszgz: false,
                zgtime: '请选择注册证取证时间',
                zgtimes: '请选择注册证到期时间',
                zgz: '',
                wuzgz: '',
                xuan_list: xuan_list,
              })
              // }
            } else {
              xuan_list[2].checked = true;
              that.setData({
                // iszcz: true,
                // cyzdatequ: data.registerPuttime,
                // cyzdatequs: data.registerPuttime,
                // cyzdatedao: data.registerEndtime,
                // cyzdatedaos: data.registerEndtime,
                // cyz: data.registerPhoto_thum,
                // wucyz: data.registerPhoto,
                // xuan_list: xuan_list,
                  iszgz: true,
                zgtimes: data.registerPuttime,
                zgtime: data.registerEndtime,
                zgz: data.registerPhoto_thum,
                wuzgz: data.registerPhoto,
                xuan_list: xuan_list,
              })
            }
            // 资格证
            if (data.practiceImage == '' || data.practiceImage == null) {
              xuan_list[1].checked = false;
              that.setData({
                // iszgz: false,
                // zgtime: '请选择资格证取证时间',
                // zgtimes: '',
                // zgz: '',
                // wuzgz: '',
                // xuan_list: xuan_list,
                iszcz: false,
                cyz: '',
                wucyz: '',
                cyzdatequ: '请选择资格证取证时间',
                cyzdatequs: '',
                cyzdatedao: '请选择资格证有效期',
                cyzdatedaos: '',
                xuan_list: xuan_list,
              })
            } else {
              xuan_list[1].checked = true;
              that.setData({
                // iszgz: true,
                // zgtime: data.practicestarTime,
                // zgtimes: data.practiceendTime,
                // zgz: data.practiceImage_thum,
                // wuzgz: data.practiceImage,
                // xuan_list: xuan_list,
                iszcz: true,
                cyzdatequ: data.practicestarTime,
                cyzdatequs: data.practicestarTime,
                cyzdatedao: data.practiceendTime,
                cyzdatedaos: data.practiceendTime,
                cyz: data.practiceImage_thum,
                wucyz: data.practiceImage,
                xuan_list: xuan_list,
              })
            }

            // 其他证件
            if (data.thatImage.length == 0 || data.thatImage == null) {
              // if (that.data.yiyao == 6) {
              //   xuan_list[1].checked = false;
              //   that.setData({
              //     iszcz: false,
              //     cyz: '',
              //     wucyz: '',
              //     xuan_list: xuan_list,
              //     cyzdatequ: '请选择注册证取证时间',
              //     cyzdatequs: '',
              //     cyzdatedao: '请选择注册证有效期',
              //     cyzdatedaos: '',
              //   })
              // } else {
              xuan_list[3].checked = false;
              that.setData({
                otherszheng: false,
                otherimg: '',
                thatImage: '',
                otherqu: '请选择其他证件取证时间',
                thatStartime: '',
                otheryou: '请选择其他证件有效期',
                thatEndtime: '',
                xuan_list: xuan_list,
              })
              // }
            } else {
              xuan_list[3].checked = true;
              const str = data.thatImage[0];
              const result = str.replace(/^https:\/\/msion\.86wky\.com/, '');
              console.log(result);
              that.setData({
                otherszheng: true,
                otherimg: data.thatImage[0],
                wuotherimg: result,
                otherqu: data.thatStartime,
                thatStartime: data.thatStartime,
                otheryou: data.thatEndtime,
                thatEndtime: data.thatEndtime,
                xuan_list: xuan_list,
              })
            }

          } else {
            // 从业证
            if (data.practiceendTime == '' || data.practiceImage_thum == null) {
              // if (that.data.yiyao == 6) {
              //   xuan_list[1].checked = false;
              //   that.setData({
              //     iszcz: false,
              //     cyz: '',
              //     wucyz: '',
              //     xuan_list: xuan_list,
              //     cyzdatequ: '请选择从业证取证时间',
              //     cyzdatequs: '',
              //     cyzdatedao: '请选择从业证有效期',
              //     cyzdatedaos: '',
              //   })
              // } else {
              xuan_list[1].checked = false;
              that.setData({
                iszcz: false,
                cyz: '',
                wucyz: '',
                cyzdatequ: '请选择从业证取证时间',
                cyzdatequs: '',
                cyzdatedao: '请选择从业证有效期',
                cyzdatedaos: '',
                xuan_list: xuan_list,
              })
              // }
            } else {
              xuan_list[1].checked = true;
              that.setData({
                iszcz: true,
                cyzdatequ: data.practicestarTime,
                cyzdatequs: data.practicestarTime,
                cyzdatedao: data.practiceendTime,
                cyzdatedaos: data.practiceendTime,
                cyz: data.practiceImage_thum,
                wucyz: data.practiceImage,
                xuan_list: xuan_list,
              })
            }
            // 其他证件
            if (data.thatImage.length == 0 || data.thatImage == null) {
              // if (that.data.yiyao == 6) {
              //   xuan_list[1].checked = false;
              //   that.setData({
              //     iszcz: false,
              //     cyz: '',
              //     wucyz: '',
              //     xuan_list: xuan_list,
              //     cyzdatequ: '请选择注册证取证时间',
              //     cyzdatequs: '',
              //     cyzdatedao: '请选择注册证有效期',
              //     cyzdatedaos: '',
              //   })
              // } else {
              xuan_list[2].checked = false;
              that.setData({
                otherszheng: false,
                otherimg: '',
                thatImage: '',
                otherqu: '请选择其他证件取证时间',
                thatStartime: '',
                otheryou: '请选择其他证件有效期',
                thatEndtime: '',
                xuan_list: xuan_list,
              })
              // }
            } else {
              xuan_list[2].checked = true;
              const str = data.thatImage[0];
              const result = str.replace(/^https:\/\/msion\.86wky\.com/, '');
              console.log(result);
              that.setData({
                otherszheng: true,
                otherimg: data.thatImage[0],
                wuotherimg: result,
                otherqu: data.thatStartime,
                thatStartime: data.thatStartime,
                otheryou: data.thatEndtime,
                thatEndtime: data.thatEndtime,
                xuan_list: xuan_list,
              })
            }
          }

        }

      }
    })
  },
  // 职位
  Position(e) {
    if ((chaninese.test(e.detail.value))) {
      wx.showToast({
        title: '只允许输入中文',
        icon: 'none'
      })
      this.setData({
        Position: ''
      })
    } else {
      this.setData({
        Position: e.detail.value
      })
    }
  },
  //毕业证选择取证时间
  bindbiye(e) {
    this.setData({
      bytime: e.detail.value,
      bytimes: e.detail.value,
      byis_dian: true
    })
    console.log(this.data.bytime)
  },
  //资格证选择取证时间
  bindzige: function (e) {
    this.setData({
      zgtime: e.detail.value,
      zgis_dian: true
    })
  },
  // 泾河保存验证
  jing_xubaocun() {
    var that = this
    if (this.data.xingming == '') {
      wx.showToast({
        title: '请输入姓名',
        icon: 'none'
      })
    } else if (this.data.dianhua == '') {
      wx.showToast({
        title: '请输入联系电话',
        icon: 'none'
      })
    } else if (this.data.dianhua.length != 11) {
      wx.showToast({
        title: '请输入11位手机号',
        icon: 'none'
      })
    } else if (mobile.test(this.data.dianhua) == false) {
      wx.showToast({
        title: '请输入正确的手机号',
        icon: 'none'
      })
    } else if (this.data.shenfenz == '') {
      wx.showToast({
        title: '请输入身份证号',
        icon: 'none'
      })
    } else if (this.data.shenfenz.length != 18) {
      wx.showToast({
        title: '请输入18位身份证号',
        icon: 'none'
      })
    } else if (sfzza.test(this.data.shenfenz) == false) {
      wx.showToast({
        title: '请输入有效身份证号',
        icon: 'none'
      })
    } else if (this.data.Position == '') {
      wx.showToast({
        title: '请输入职务',
        icon: 'none'
      })
    } else if (!this.data.isjkz && !this.data.isbyz && !this.data.iszcz && !this.data.iszgz) {
      this.update()
    } else {
      // 选了健康证
      if (this.data.isjkz) {
        console.log('走了健康证')
        if (this.data.date == '请选择健康证取证时间') {
          wx.showToast({
            title: '请选择健康证取证时间',
            icon: 'none'
          })
          return
        }
        if (this.data.jkz == '') {
          wx.showToast({
            title: '请上传健康证',
            icon: 'none'
          })
          return
        }
      } else {
        // date == '请选择健康证取证时间'
        that.setData({
          date: '请选择健康证取证时间'
        })
      }
      // 走了毕业证 
      if (this.data.isbyz) {
        console.log('走了毕业证 ')
        if (this.data.bytime == '请选择毕业证取证时间') {
          wx.showToast({
            title: '请选择毕业证取证时间',
            icon: 'none'
          })
          return
        }
        if (this.data.byz == '') {
          wx.showToast({
            title: '请上传毕业证',
            icon: 'none'
          })
          return
        }
      } else {
        that.setData({
          bytime: '请选择毕业证取证时间'
        })
      }
      // 走了注册证 
      if (this.data.iszcz) {
        console.log('走了注册证')
        if (this.data.cyzdatequ == '请选择注册证取证时间') {
          wx.showToast({
            title: '请选择注册证取证时间',
            icon: 'none'
          })
          return
        }
        if (this.data.cyzdatedao == '请选择注册证有效期') {
          wx.showToast({
            title: '请选择注册证有效期',
            icon: 'none'
          })
          return
        }
        if (this.data.cyz == '') {
          wx.showToast({
            title: '请上传注册证',
            icon: 'none'
          })
          return
        }
      } else {
        that.setData({
          cyzdatedao: '请选择注册证有效期'
        })
      }
      // 走了资格证
      if (this.data.iszgz) {
        console.log('走了资格证')
        if (this.data.zgtime == '请选择资格证有效期') {
          wx.showToast({
            title: '请选择资格证有效期',
            icon: 'none'
          })
          return
        }
        if (this.data.zgz == '') {
          wx.showToast({
            title: '请上传资格证',
            icon: 'none'
          })
          return
        }
      } else {
        that.setData({
          zgtime: '请选择资格证取证时间'
        })
      }
      this.update()
    }
  },
  xubaocun() {
    if (this.data.xingming == '') {
      wx.showToast({
        title: '请输入姓名',
        icon: 'none'
      })
    } else if (this.data.dianhua == '') {
      wx.showToast({
        title: '请输入联系电话',
        icon: 'none'
      })
    } else if (this.data.dianhua.length != 11) {
      wx.showToast({
        title: '请输入11位手机号',
        icon: 'none'
      })
    } else if (mobile.test(this.data.dianhua) == false) {
      wx.showToast({
        title: '请输入正确的手机号',
        icon: 'none'
      })
    } else if (this.data.shenfenz == '') {
      wx.showToast({
        title: '请输入身份证号',
        icon: 'none'
      })
    } else if (this.data.shenfenz.length != 18) {
      wx.showToast({
        title: '请输入18位身份证号',
        icon: 'none'
      })
    } else if (sfzza.test(this.data.shenfenz) == false) {
      wx.showToast({
        title: '请输入有效身份证号',
        icon: 'none'
      })
    } else if (this.data.Position == '') {
      wx.showToast({
        title: '请输入职务',
        icon: 'none'
      })
    } else if (!this.data.isjkz && !this.data.isbyz && !this.data.iszcz && !this.data.iszgz) {
      this.updates()
    } else {
      // 选了健康证
      if (this.data.isjkz) {
        console.log('走了健康证')
        if (this.data.date == '请选择健康证取证时间') {
          wx.showToast({
            title: '请选择健康证取证时间',
            icon: 'none'
          })
          return
        }
        if (this.data.jkz == '') {
          wx.showToast({
            title: '请上传健康证',
            icon: 'none'
          })
          return
        }
      }
      // 走了注册证 
      if (this.data.iszcz) {
        console.log('走了注册证')
        // if (this.data.cyzzjlx == '') {
        //   wx.showToast({
        //     title: '请输入从业证岗位',
        //     icon: 'none'
        //   })
        //   return
        // }
        if (this.data.cyzdatequ == '请选择从业证取证时间') {
          wx.showToast({
            title: '请选择从业证取证时间',
            icon: 'none'
          })
          return
        }
        if (this.data.cyzdatedao == '请选择从业证有效期') {
          wx.showToast({
            title: '请选择从业证有效期',
            icon: 'none'
          })
          return
        }
        if (this.data.cyz == '') {
          wx.showToast({
            title: '请上传从业证',
            icon: 'none'
          })
          return
        }
      }
      this.updates()
    }
  },
  // 修改
  update() {
    var that = this
    wx.showModal({
      title: '确定要提交吗?',
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          if (that.data.date == '请选择健康证取证时间') {
            that.setData({
              date: '',
              wujkz: '',
            })
          }
          if (that.data.dates == '请选择健康证有效时间') {
            that.setData({
              dates: ''
            })
          }
          if (that.data.bytime == '请选择毕业证取证时间') {
            that.setData({
              bytime: '',
              bytimes: '',
              wubyz: ''
            })
          }
          if (that.data.cyzdatequ == '请选择注册证取证时间') {
            that.setData({
              cyzdatequ: '',
              cyzdatequs: ''
            })
          }
          if (that.data.cyzdatedao == '请选择注册证有效期') {
            that.setData({
              cyzdatedao: '',
              cyzdatedaos: "",
              cyzdatequs: '',
              wucyz: '',
            })
          }
          if (that.data.zgtime == '请选择资格证取证时间') {
            that.setData({
              zgtime: '',
              zgtimes: '',
              wuzgz: '',
            })
          }
          that.setData({
            buttonClicked: true
          })
          let data = {
            shopId: wx.getStorageSync('shopId'),
            id: that.data.id,
            Name: that.data.xingming,
            Phone: that.data.dianhua,
            idNumber: that.data.shenfenz,
            Position: that.data.Position,
            healthyDcment: that.data.jkzzjlx,
            obtainTime: that.data.date,
            effectiveTime: that.data.dates,
            healthyImage: that.data.wujkz,
            practiceDcment: that.data.cyzzjlx,
            practicestarTime: that.data.zgtimes, //资格证领证时间
            practiceendTime: that.data.zgtime, //资格证到期时间
            practiceImage: that.data.wuzgz, //资格证
            graduationPhoto: that.data.wubyz, //毕业照
            graduationPuttime: that.data.bytimes, //毕业证取证时间
            registerPhoto: that.data.wucyz, //注册证
            registerEndtime: that.data.cyzdatedaos, //注册证取证时间
            registerPuttime: that.data.cyzdatequs, //注册证到期时间
            
          };
          var urlda = ''
          if (wx.getStorageSync('jinghe_id') != 176) {
            urlda = 'shop/shopSaveStaff'
          }
          if (wx.getStorageSync('jinghe_id') == 176) {
            urlda = 'Jinghexincheng/shopSaveStaff'
          }
          that.myRequest(yuming + urlda, data, 'POST').then(res => {
            console.log(res)
            wx.showToast({
              title: res.data.msg,
              icon: 'none'
            })
            if (res.data.code == 200) {
              setTimeout(function () {
                // wx.reLaunch({
                //   url: '/view/index/congye/congye',
                // })
                wx.navigateBack({
                  delta: 0
                })
              }, 1000)
            } else {
              that.setData({
                buttonClicked: false
              })
            }
          })
        } else {
          console.log("取消")
        }
      }
    })

  },
  updates() {
    var that = this
    wx.showModal({
      title: '确定要提交吗?',
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          if (that.data.date == '请选择健康证取证时间') {
            that.setData({
              date: ''
            })
          }
          if (that.data.dates == '请选择健康证有效时间') {
            that.setData({
              dates: ''
            })
          }
          if (that.data.bytime == '请选择毕业证取证时间') {
            that.setData({
              bytime: '',
              bytimes: ''
            })
          }
          if (that.data.cyzdatequ == '请选择注册证取证时间') {
            that.setData({
              cyzdatequ: '',
              cyzdatequs: ''
            })
          }
          if (that.data.cyzdatedao == '请选择注册证有效期') {
            that.setData({
              cyzdatedao: '',
              cyzdatedaos: ''
            })
          }
          if (that.data.zgtime == '请选择资格证取证时间') {
            that.setData({
              zgtime: '',
              zgtimes: ''
            })
          }
          that.setData({
            buttonClicked: true
          })
          let data = {
            shopId: wx.getStorageSync('shopId'),
            id: that.data.id,
            Name: that.data.xingming,
            Phone: that.data.dianhua,
            idNumber: that.data.shenfenz,
            Position: that.data.Position,
            healthyDcment: that.data.jkzzjlx,
            obtainTime: that.data.date,
            effectiveTime: that.data.dates,
            healthyImage: that.data.wujkz,
            // practiceDcment: that.data.cyzzjlx,
            // practicestarTime: that.data.zgtimes, //从业资格证领证时间
            // practiceendTime: that.data.cyzdatedaos, //从业资格证到期时间
            // practiceImage: that.data.wuzgz, //从业资格证
            practicestarTime: that.data.cyzdatequs, //从业资格证领证时间
            practiceendTime: that.data.cyzdatedaos, //从业资格证到期时间
            practiceImage: that.data.wucyz, //从业资格证

            graduationPhoto: that.data.wubyz, //毕业照
            graduationPuttime: that.data.bytimes, //毕业证取证时间
            registerPhoto: that.data.wuzgz, //注册证
            registerPuttime: that.data.zgtime, //注册证取证时间
            registerEndtime: that.data.zgtimes, //注册证到期时间
            thatImage: that.data.wuotherimg,
            thatStartime: that.data.otherqu,
            thatEndtime: that.data.otheryou
          };
          var urlda = ''
          if (wx.getStorageSync('jinghe_id') != 176) {
            urlda = 'shop/shopSaveStaff'
          }
          if (wx.getStorageSync('jinghe_id') == 176) {
            urlda = 'Jinghexincheng/shopSaveStaff'
          }
          console.log(data);
          that.myRequest(yuming + urlda, data, 'POST').then(res => {
            console.log(res)
            wx.showToast({
              title: res.data.msg,
              icon: 'none'
            })
            if (res.data.code == 200) {
              setTimeout(function () {
                wx.navigateBack({
                  delta: 0
                })
              }, 1000)
            } else {
              that.setData({
                buttonClicked: false
              })
            }
          })
        } else {
          console.log("取消")
        }
      }
    })

  },
  // 输入健康证类型
  jkzzjlx(e) {
    if ((chaninese.test(e.detail.value))) {
      wx.showToast({
        title: '只允许输入中文',
        icon: 'none'
      })
      this.setData({
        jkzzjlx: ''
      })
    } else {
      this.setData({
        jkzzjlx: e.detail.value
      })
    }
  },
  // 输入从业证类型
  cyzzjlx(e) {
    if ((chaninese.test(e.detail.value))) {
      wx.showToast({
        title: '只允许输入中文',
        icon: 'none'
      })
      this.setData({
        cyzzjlx: ''
      })
    } else {
      this.setData({
        cyzzjlx: e.detail.value
      })
    }
  },
  //点击放大
  // fangda(e) {
  //   var img = e.currentTarget.dataset.img
  //   var that = this
  //   var aaa = e.currentTarget.dataset.aaa
  //   wx.showModal({
  //     title: '您是想实现哪种操作',
  //     cancelText: '重新上传',
  //     confirmText: '放大',
  //     success: function (res) {
  //       if (res.confirm) {
  //         console.log("放大")
  //         wx.previewImage({
  //           urls: [img]
  //         })
  //       } else {
  //         wx.chooseImage({
  //           success: function (res) {
  //             var tempFilePaths = res.tempFilePaths
  //             wx.uploadFile({
  //               url: yuming + 'Besall/Upload',
  //               filePath: tempFilePaths[0],
  //               name: "file",
  //               formData: {

  //               },
  //               success(res) {
  //                 var data = JSON.parse(res.data)
  //                 wx.showToast({
  //                   title: data.msg,
  //                   icon: 'none'
  //                 })
  //                 var urls = data.httpUrl + data.imgUrl
  //                 if (aaa == 0) {
  //                   that.setData({
  //                     jkz: urls
  //                   });
  //                 }
  //                 if (aaa == 1) {
  //                   that.setData({
  //                     cyz: urls
  //                   });
  //                 }
  //               }
  //             })
  //           }
  //         })
  //       }
  //     }
  //   })
  // },
  // 上传
  chuan(e) {
    var aaa = e.currentTarget.dataset.aaa //店头营业执照
    var that = this;
    this.myChooseImage(1).then(res => {
      const tempFilePaths = res.tempFilePaths
      this.myUploadImg(tempFilePaths[0], 'file').then(res => {
        var data = JSON.parse(res.data)
        wx.showToast({
          title: data.msg,
          icon: 'none'
        })
        var urls = data.httpUrl + data.imgUrl
        if (aaa == 0) {
          that.setData({
            jkz: urls,
            wujkz: data.imgUrl,
            jkis_dian: true,
          });
        }
        if (aaa == 1) {
          that.setData({
            cyz: urls,
            wucyz: data.imgUrl,
            zcis_dian: true
          });
        }
        if (aaa == 2) {
          that.setData({
            byz: urls,
            wubyz: data.imgUrl,
            byis_dian: true
          });
        }
        if (aaa == 3) {
          that.setData({
            zgz: urls,
            wuzgz: data.imgUrl,
            zgis_dian: true
          });
        }
        if (aaa == 4) {
          that.setData({
            otherimg: urls,
            wuotherimg: data.imgUrl,
            // zgis_dian: true
          });
        }
      })
    })
  },
  // 职位
  zhiwei(e) {
    let index = e.detail.value
    this.setData({
      zhiguo: this.data.zhilist[e.detail.value].name,
      zhiweiid: this.data.zhilist[e.detail.value].id
    });
  },
  // 填写姓名
  xingming(e) {
    this.setData({
      xingming: e.detail.value
    })
  },
  // 填写电话
  dianhua(e) {
    var value = e.detail.value
    console.log(value)
    if (!chaninese.test(value)) {
      wx.showToast({
        title: '只能输入数字！',
        icon: 'error'
      })
      this.setData({
        dianhua: ''
      })
    }
    if (value.length == 11) {
      if (!mobile.test(value)) {
        wx.showToast({
          title: '格式不正确！',
          icon: 'error'
        })
      } else {
        this.setData({
          dianhua: value
        })
      }
    }
  },
  // 填写身份证
  shenfenz(e) {
    this.setData({
      shenfenz: e.detail.value
    })
  },
  // 健康证选择开始时间
  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value,
      jkis_dian: true
    })
    let date = new Date(this.data.date);
    let year = date.getFullYear() + 1
    let month = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1);
    let day = (date.getDate() < 10 ? "0" + (date.getDate()) : date.getDate());
    this.setData({
      dates: year + '-' + month + '-' + day
    })
  },
  // 健康证选择结束时间
  // bindDateChanges: function (e) {
  //   if (new Date(e.detail.value).getTime() < Date.parse(new Date())) {
  //     wx.showToast({
  //       title: '有效期不可小于当前时间',
  //       icon: 'none'
  //     })
  //     this.setData({
  //       dates: '请选择健康证有效期'
  //     })
  //   } else {
  //     this.setData({
  //       dates: e.detail.value
  //     })
  //   }
  // },
  // 从业证选择开始时间
  bindcyzqu: function (e) {
    this.setData({
      cyzdatequ: e.detail.value,
      cyzdatequs: e.detail.value,
      zcis_dian: true
    })
  },
  // 从业证选择结束时间
  bindcyzdao: function (e) {
    if (new Date(e.detail.value).getTime() < Date.parse(new Date())) {
      wx.showToast({
        title: '有效期不可小于当前时间',
        icon: 'none'
      })
      this.setData({
        cyzdatedao: '请选择从业证有效期'
      })
    } else {
      this.setData({
        cyzdatedao: e.detail.value,
        cyzdatedaos: e.detail.value
      })
    }
  },
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      id: options.id,
      Position: options.Position,
      jinghe_id: wx.getStorageSync('jinghe_id'),
      yiyao: wx.getStorageSync('stryId')

    })
    console.log(options)
    if (this.data.jinghe_id == 176) {
      this.setData({
        xuan_list: [{
          name: '健康证',
          checked: false
        }, {
          name: '毕业证',
          checked: false
        }, {
          name: '注册证',
          checked: false
        }, {
          name: '资格证',
          checked: false
        }]
      })
    } else {


      if (this.data.yiyao == 6) {
        this.setData({
          xuan_list: [{
              name: '健康证',
              checked: false
            }, {
              name: '资格证',
              checked: false
            },
            {
              name: '注册证',
              checked: false
            }, {
              name: '其他证照',
              checked: false
            }
          ]
        })
      } else {
        this.setData({
          xuan_list: [{
            name: '健康证',
            checked: false
          }, {
            name: '从业证',
            checked: false
          }, {
            name: '其他证照',
            checked: false
          }]
        })
      }
    }
    this.ygxq()
  },
  goqtcy(e) {
    wx.navigateTo({
      url: '/page_other/qitacy/qitacy',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      zhan: wx.getStorageSync('zhan'),
      yiyao: wx.getStorageSync('stryId')
    })
    if (this.data.zhan == 99) {
      this.setData({
        cyz: wx.getStorageSync('cyimg'),
        cyzdatequ: wx.getStorageSync('cystartime'),
        cyzdatedao: wx.getStorageSync('cyendtime')
      })
      console.log(this.data.cyz)
    }
    console.log(this.data.cyz)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})